#include "StdAfx.h"
#include <time.h>
#include "Utility.h"
#include "Logger.h"


UINT CalcSquareWidth(const CRect& rect, UINT nRow, UINT nCol)
{
    ASSERT(rect.Height() != 0 && rect.Width() != 0);
    ASSERT(nRow !=0 && nCol != 0);

    UINT nResult = 0;

    double fHeightScale = rect.Height() / (double)nRow;
    double fWidthScale = rect.Width() / (double)nCol;

    if (fHeightScale >= fWidthScale)
    {
        nResult = fWidthScale;
    }
    else
    {
        nResult = fHeightScale;
    }

    return nResult;
}

double Random()
{
    long TmpSeed;
    TmpSeed = A * (Seed % Q) - R * (Seed / Q); 
    if(TmpSeed>=0)
    {
         Seed = TmpSeed;
    }
    else 
    {
         Seed = TmpSeed + M; 
    }

    return (double) Seed / M; 
}

UINT GetRandomNumber(UINT min, UINT max)
{
	ASSERT(min<=max);

	UINT nResult;

	if(min == max)
	{
		nResult = min;
	}
	else
	{
		nResult = min + Random() * (max - min + 1);
	}
     
	return nResult;
}

std::string GetTimeString()
{
    time_t now = time(NULL);
    char * szTime = ctime(&now);

    return std::string(szTime, strlen(szTime) - 1);
}